//
//  OSCSoftwareDetails.m
//  oschina_song
//
//  Created by song on 16/1/31.
//  Copyright © 2016年 song. All rights reserved.
//

#import "OSCSoftwareDetails.h"
#import "Utils.h"

@implementation OSCSoftwareDetails


-(id)initWithXML:(ONOXMLElement *)xml
{
    self = [super init];
    
    if (self) {
        _authorID = [xml firstChildWithTag:@"authorid"].numberValue.integerValue;
        _author = [xml firstChildWithTag:@"author"].stringValue ?: @"";
        _softwareID = [[[xml firstChildWithTag:@"id"] numberValue] longLongValue];
        _isRecommended = [xml firstChildWithTag:@"recommended"].numberValue.boolValue;
        _title = [[xml firstChildWithTag:@"title"] stringValue];
        _extensionTitle = [[xml firstChildWithTag:@"extensionTitle"] stringValue];
        _license = [[xml firstChildWithTag:@"license"] stringValue];
        _body = [[xml firstChildWithTag:@"body"] stringValue];
        _os = [[xml firstChildWithTag:@"os"] stringValue];
        _language = [[xml firstChildWithTag:@"language"] stringValue];
        _recordTime = [[xml firstChildWithTag:@"recordtime"] stringValue];
        _url = [NSURL URLWithString:[[xml firstChildWithTag:@"url"] stringValue]];
        _homepageURL = [[xml firstChildWithTag:@"homepage"] stringValue];
        _documentURL = [[xml firstChildWithTag:@"document"] stringValue];
        _downloadURL = [[xml firstChildWithTag:@"download"] stringValue];
        _logoURL = [[xml firstChildWithTag:@"logo"] stringValue];
        _isFavorite = [[[xml firstChildWithTag:@"favorite"] numberValue] boolValue];
        _tweetCount = [[[xml firstChildWithTag:@"tweetCount"] numberValue] intValue];
    }
    
    return self;
}

-(NSString *)html
{
    if(!_html)
    {
        NSDictionary *data = @{
                               @"logoURL":_logoURL,
                               @"title":_title,
                               @"content":_body,
                               @"license":_license,
                               @"language":_language,
                               @"os":_os,
                               @"recordTime":_recordTime,
                               };
        _html =[Utils htmlWithData:data usingTemple:@"software"];
        

    }
    
    return _html;
}

@end
